Separate the numbers and get their position¶
Separate and print the numbers and their position of a given string.
import re
text = "The following example creates an ArrayList with a \
capacity of 50 elements. Four elements are then added \
to the ArrayList4 and the ArrayList4 is trimmed accordingly."
for m in re.finditer("\d+", text):
print(m.group(0))
print("Index position:", m.start())
Output:
50
Index position: 63
4
Index position: 122
4
Index position: 141